package com.example.yuejianapp14.Activity.Activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.yuejianapp14.Activity.JavaBean.Act;
import com.example.yuejianapp14.Activity.JavaBean.Success;
import com.example.yuejianapp14.Activity.JavaBean.class1;
import com.example.yuejianapp14.Activity.Listener.ClassInfoListener;
import com.example.yuejianapp14.Activity.Listener.ClubNoListListener;
import com.example.yuejianapp14.Activity.Listener.ListListener;
import com.example.yuejianapp14.Activity.Model.ActivityModel;
import com.example.yuejianapp14.Activity.Model.ClassModel;
import com.example.yuejianapp14.Activity.Model.EnterModel;
import com.example.yuejianapp14.R;
import com.squareup.picasso.Picasso;

public class ActActivity extends AppCompatActivity {
    private ImageView act_pic;
    private TextView act_address,act_time,act_cost,act_phone,act_info,act_name;
    private Context mContext;
    private String act_id;
    private Button actbtn;
    private SharedPreferences sp;
    String etype;
    String etypeid;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_act);
        initViews();
        getData();
        actbtn();
        Intent intent=getIntent();
        intent.getStringExtra("actid");
        etypeid= intent.getStringExtra("actid");
        Picasso.with(mContext).load("http://10.0.2.2/YueJian/Public/photo/activity/"+getIntent().getStringExtra("actpic")).into(act_pic);
    }

    public void initViews(){
        act_info = (TextView) findViewById(R.id.act_info);
        act_cost = (TextView) findViewById(R.id.act_cost);
        act_address = (TextView) findViewById(R.id.act_address);
        act_time = (TextView) findViewById(R.id.act_time);
        act_pic=(ImageView)findViewById(R.id.Act_pic);
        act_phone=(TextView) findViewById(R.id.act_phone);
        act_name=(TextView) findViewById(R.id.act_name);
        actbtn=(Button) findViewById(R.id.act_enter);
        sp=getSharedPreferences("uid",MODE_PRIVATE);

    }

    ClubNoListListener<Act> clubNoListListener =new ClubNoListListener<Act>() {
        @Override
        public void onResponse(Act act) {
            act_info.setText(act.getInstruction());
            act_cost.setText("¥"+act.getCost());
            act_address.setText(act.getAddress());
            act_time.setText(act.getTime());
            act_phone.setText(act.getContact());
            act_name.setText(act.getActivity());
        }

        @Override
        public void onFail(String msg) {

        }
    };


    private void getData() {
        Intent intent = getIntent();
        ActivityModel activityModel =new ActivityModel();
        activityModel.actinfo(intent.getStringExtra("actid"),clubNoListListener);
    }

    private void actbtn(){
          actbtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  EnterModel enterModel =new EnterModel();
                  enterModel.enter(sp.getString("uid",""),"2",etypeid, EnterListener);
              }
          });
    }

    ListListener<Success> EnterListener = new ListListener<Success>() {
        @Override
        public void onResponse(Success a) {
            if (a.getSuccess().equals("1")) {
                Toast.makeText(ActActivity.this, "报名成功", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(ActActivity.this, "报名失败", Toast.LENGTH_SHORT).show();

        }
    };


}
